<?php

class My_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract{
          public function preDispatch(Zend_Controller_Request_Abstract $request) {
                  //$this->getResponse()->appendBody('<p>preDispatch()</p>');
                  if (Zend_Auth::getInstance()->hasIdentity()){
                          $idacc= Zend_Auth::getInstance()->getStorage()->read()->idacctype;
                          
                          $db = Zend_Db_Table::getDefaultAdapter();
                          $query = $db->select()
                            ->from('acctype','type')
                            ->where('idacctype = ?', $idacc);
                          $result= $db->fetchRow($query);
                          
                          $role=$result['type'];
                 }
                 else{
                         $role = 'gosc';
                 }
 
                 $acl = new My_Acl();
                 if (!$acl->isAllowed(
                         $role,
                         $request->getControllerName(),
                         $request->getActionName()
                 )) {
                     $request->setModuleName('default')
                             ->setControllerName('index')
                             //->setControllerName($request->getControllerName())
                             ->setActionName('logowanie')
                             ->setDispatched(false);
                     //throw new Zend_Exception('Access Denied!');
                 }
         }
 /*
         public function routeStartup(){
         $this->getResponse()->appendBody('<p>routeStartup()</p>');
    }
 
     public function routeShutdown($request){
         $this->getResponse()->appendBody('<p>routeShutdown()</p>');
     }
     public function dispatchLoopStartup($request){
         $this->getResponse()->appendBody('<p>dispatchLoopStartup()</p>');
     }
 
     public function postDispatch($request){
         $this->getResponse()->appendBody('<p>postDispatch()</p>');
     }
 
     public function dispatchLoopShutdown(){
         $this->getResponse()->appendBody('<p>dispatchLoopShutdown()/p>');
     }
 */
 }
